*
* The main properties of a GtkSpinButton are through an adjustment.
* See the #GtkAdjustment section for more details about an adjustment's
- * properties. Note that GtkSpinButton will by default make its entry
- * large enough to accomodate the lower and upper bounds of the adjustment,
- * which can lead to surprising results. Best practice is to set both
- * the #GtkEntry:width-chars and #GtkEntry:max-width-chars poperties
- * to the desired number of characters to display in the entry.
+ * properties.
+ *
+ * Note that GtkSpinButton will by default make its entry large enough to
+ * accomodate the lower and upper bounds of the adjustment. If this is
+ * not desired, the automatic sizing can be turned off by explicitly
+ * setting #GtkSpinButton::width-chars to a value != -1.
*
* # CSS nodes
*
gdouble climb_rate;
gdouble timer_step;
+ int width_chars;
+
GtkOrientation orientation;
guint digits : 10;
gdouble *new_val);
static void gtk_spin_button_default_output (GtkSpinButton *spin_button);
+static void gtk_spin_button_update_width_chars (GtkSpinButton *spin_button);
+
static guint spinbutton_signals[LAST_SIGNAL] = {0};
static GParamSpec *spinbutton_props[NUM_SPINBUTTON_PROPS] = {NULL, };
{
GtkSpinButton *spin_button = GTK_SPIN_BUTTON (object);
+ if (prop_id == PROP_EDITING_CANCELED + 1 + GTK_EDITABLE_PROP_WIDTH_CHARS)
+ {
+ spin_button->width_chars = g_value_get_int (value);
+ gtk_spin_button_update_width_chars (spin_button);
+ return;
+ }
+
if (gtk_editable_delegate_set_property (object, prop_id, value, pspec))
return;
{
GtkSpinButton *spin_button = GTK_SPIN_BUTTON (object);
+ if (prop_id == PROP_EDITING_CANCELED + 1 + GTK_EDITABLE_PROP_WIDTH_CHARS)
+ {
+ g_value_set_int (value, spin_button->width_chars);
+ return;
+ }
if (gtk_editable_delegate_get_property (object, prop_id, value, pspec))
return;
spin_button->numeric = FALSE;
spin_button->wrap = FALSE;
spin_button->snap_to_ticks = FALSE;
+ spin_button->width_chars = -1;
spin_button->orientation = GTK_ORIENTATION_HORIZONTAL;
return weed_out_neg_zero (buf, spin_button->digits);
}
+static void
+gtk_spin_button_update_width_chars (GtkSpinButton *spin_button)
+{
+ char *str;
+ double value;
+ int width_chars, c;
+
+ if (spin_button->width_chars == -1)
+ {
+ width_chars = 0;
+
+ value = gtk_adjustment_get_lower (spin_button->adjustment);
+ str = gtk_spin_button_format_for_value (spin_button, value);
+ c = g_utf8_strlen (str, -1);
+ g_free (str);
+
+ width_chars = MAX (width_chars, c);
+
+ value = gtk_adjustment_get_upper (spin_button->adjustment);
+ str = gtk_spin_button_format_for_value (spin_button, value);
+ c = g_utf8_strlen (str, -1);
+ g_free (str);
+
+ width_chars = MAX (width_chars, c);
+
+ width_chars = MIN (width_chars, 10);
+ }
+ else
+ width_chars = spin_button->width_chars;
+
+ gtk_editable_set_width_chars (GTK_EDITABLE (spin_button->entry), width_chars);
+}
+
static void
gtk_spin_button_grab_notify (GtkWidget *widget,
gboolean was_grabbed)
***********************************************************
***********************************************************/
-
/**
* gtk_spin_button_configure:
* @spin_button: a #GtkSpinButton
g_object_notify_by_pspec (G_OBJECT (spin_button), spinbutton_props[PROP_CLIMB_RATE]);
}
+ gtk_spin_button_update_width_chars (spin_button);
+
g_object_thaw_notify (G_OBJECT (spin_button));
gtk_spin_button_value_changed (adjustment, spin_button);